const session = require("express-session");
const { REDIS_SESSION_KEY } = require("../server-env");
const RedisStore = require("connect-redis").default;
const redisClient = require('../storage/redis-client');

// Initialize store.
let redisStore = new RedisStore({
  client: redisClient,
  prefix: "myapp:",
});

const redisSessionRouter = session({
  store: redisStore,
  resave: false, // required: force lightweight session keep alive (touch)
  saveUninitialized: false, // recommended: only save session when data exists
  secret: REDIS_SESSION_KEY
});

module.exports = redisSessionRouter;
